.\" Copyright (c) 2007-2018 Julien Nadeau Carriere <vedge@csoft.net>
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\" 
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
.\" INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
.\" (INCLUDING BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
.\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
.\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd October 12, 2007
.Dt AG_GLVIEW 3
.Os
.ds vT Agar API Reference
.ds oS Agar 1.2
.Sh NAME
.Nm AG_GLView
.Nd low-level OpenGL context widget
.Sh SYNOPSIS
.Bd -literal
#include <agar/core.h>
#include <agar/gui.h>
.Ed
.Sh DESCRIPTION
.\" IMAGE(http://libagar.org/widgets/AG_GLView.png, "The AG_GLView widget (with an OverlayFn)")
NOTE: As of version 1.5.0,
.Nm
has been superceded by the
.Dv AG_WIDGET_USE_OPENGL
feature of the base
.Xr AG_Widget 3
class.
.Pp
The
.Nm
widget provides a low-level OpenGL context.
In order to be useful, two callbacks should be implemented:
.Fn scale
and
.Fn draw .
The
.Fn scale
function is expected to set the projection matrix.
For example, the scale function may be a simple call to
.Xr glOrtho 3 .
.Pp
The
.Fn draw
function renders the scene to the display.
Before calling
.Fn draw ,
.Nm
calls
.Xr glViewport 3 .
It also sets the
.Dv GL_TEXTURE ,
.Dv GL_PROJECTION ,
.Dv GL_MODELVIEW
matrices and saves the state of the clipping planes by calling
.Xr glPushAttrib 3
with
.Dv GL_TRANSFORM_BIT .
.Pp
The
.Nm
widget is not redrawn automatically by default.
It is the responsibility of the
caller to set the redraw policy either by calling
.Xr AG_Redraw 3
to explicitely request a redraw,
configuring a periodic update interval using
.Xr AG_RedrawOnTick 3 ,
or a conditional update using
.Xr AG_RedrawOnChange 3 .
.Sh INHERITANCE HIERARCHY
.Xr AG_Object 3 ->
.Xr AG_Widget 3 ->
.Nm .
.Sh INITIALIZATION
.nr nS 1
.Ft "AG_GLView *"
.Fn AG_GLViewNew "AG_Widget *parent" "Uint flags"
.Pp
.Ft "void"
.Fn AG_GLViewSetBgColor "AG_GLView *glv" "const AG_Color *c"
.Pp
.Ft void
.Fn AG_GLViewSizeHint "AG_GLView *glv" "int w" "int h"
.Pp
.Ft void
.Fn AG_GLViewDrawFn "AG_GLView *glv" "void (*fn)(AG_Event *)" "const char *args" "..."
.Pp
.Ft void
.Fn AG_GLViewOverlayFn "AG_GLView *glv" "void (*fn)(AG_Event *)" "const char *args" "..."
.Pp
.Ft void
.Fn AG_GLViewUnderlayFn "AG_GLView *glv" "void (*fn)(AG_Event *)" "const char *args" "..."
.Pp
.Ft void
.Fn AG_GLViewScaleFn "AG_GLView *glv" "void (*fn)(AG_Event *)" "const char *args" "..."
.Pp
.Ft void
.Fn AG_GLViewKeydownFn "AG_GLView *glv" "void (*fn)(AG_Event *)" "const char *args" "..."
.Pp
.Ft void
.Fn AG_GLViewKeyupFn "AG_GLView *glv" "void (*fn)(AG_Event *)" "const char *args" "..."
.Pp
.Ft void
.Fn AG_GLViewButtondownFn "AG_GLView *glv" "void (*fn)(AG_Event *)" "const char *args" "..."
.Pp
.Ft void
.Fn AG_GLViewButtonupFn "AG_GLView *glv" "void (*fn)(AG_Event *)" "const char *args" "..."
.Pp
.Ft void
.Fn AG_GLViewMotionFn "AG_GLView *glv" "void (*fn)(AG_Event *)" "const char *args" "..."
.Pp
.nr nS 0
The
.Fn AG_GLViewNew
function allocates, initializes, and attaches a new
.Nm
widget.
Acceptable
.Fa flags
include:
.Bl -tag -width "AG_GLVIEW_EXPAND "
.It AG_GLVIEW_BGFILL
Clear the widget background with the specified color (see
.Fn AG_GLViewSetBgColor ) .
.It AG_GLVIEW_HFILL
Expand horizontally in parent container.
.It AG_GLVIEW_VFILL
Expand vertically in parent container.
.It AG_GLVIEW_EXPAND
Shorthand for
.Dv AG_GLVIEW_HFILL | AG_GLVIEW_VFILL .
.El
.Pp
.Fn AG_GLViewSetBgColor
specifies the background color (effective only if
.Dv AG_GLVIEW_BGFILL
is set).
.Pp
.Fn AG_GLViewSizeHint
suggests an initial widget size in pixels.
.Pp
The
.Fn AG_GLViewDrawFn
registers a the rendering function (specified in
.Xr AG_Event 3
format).
Prior to invoking this function, the widget will set the
.Xr glViewport 3
to the widget area, save the current OpenGL matrices and load the
widget-specific matrices.
.Pp
.Fn AG_GLViewOverlayFn
registers a function that will be invoked after rendering, after the
GUI matrices and viewport have been restored.
It is typically used to draw text or controls independently of the
projection and viewing matrices.
Similarly,
.Fn AG_GLViewUnderlayFn
registers a function that will be invoked before rendering.
Both overlay and underlay callbacks may invoke standard Agar GUI
primitives such as
.Xr AG_DrawRect 3
or
.Xr AG_WidgetBlit 3 .
.Pp
.Fn AG_GLViewScaleFn
registers a function to invoke whenever the widget is resized.
.Pp
.Fn AG_GLViewKeydownFn ,
.Fn AG_GLViewKeyupFn ,
.Fn AG_GLViewButtondownFn ,
.Fn AG_GLViewButtonupFn
and
.Fn AG_GLViewMotionFn
register general event handler functions that will be forwarded
.Sq key-down ,
.Sq key-up ,
.Sq mouse-button-down ,
.Sq mouse-button-up
and
.Sq mouse-motion
events, respectively.
.Sh BINDINGS
The
.Nm
widget does not provide any binding.
.Sh EVENTS
The
.Nm
widget does not generate any event.
.Sh STRUCTURE DATA
For the
.Ft AG_GLView
object:
.Bl -tag -compact -width "float mProjection[16] "
.It Ft float mProjection[16]
Saved Projection matrix (4x4, column-major).
.It Ft float mModelview[16]
Saved Modelview matrix.
.It Ft float mTexture[16]
Saved Texture matrix.
.El
.Sh EXAMPLES
See
.Pa tests/glview.c
in the Agar source distribution.
.Sh SEE ALSO
.Xr AG_Color 3 ,
.Xr AG_Intro 3 ,
.Xr AG_Widget 3 ,
.Xr AG_Window 3 ,
.Xr SG 3 ,
.Xr SG_View 3
.Sh HISTORY
The
.Nm
widget first appeared in Agar 1.2.
As of Agar 1.5.0, it has been superceded by the
.Dv AG_WIDGET_USE_OPENGL
feature of
.Xr AG_Widget 3 .
